﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition.Primitives;
using System.Linq.Expressions;
using System.Reflection;
using System.ComponentModel.Composition;

namespace FluentMef
{
    sealed class ConstructorFluentImportDefinition : FluentImportDefinition
    {
        public ConstructorFluentImportDefinition(Type t, string contractName) : base(t, contractName)
        {
        }
    }

    sealed class PropertyFluentImportDefinition : FluentImportDefinition
    {
        public PropertyFluentImportDefinition(PropertyInfo importMember, string contractName) : base(importMember.PropertyType, contractName)
        {
            ImportMember = importMember;
        }

        public PropertyInfo ImportMember { get; private set; }
    }

    abstract class FluentImportDefinition : ContractBasedImportDefinition
    {
        string _contractName;

        protected FluentImportDefinition(Type importType, string contractName) : base(contractName, ContractNameServices.GetTypeIdentity(importType), null, ImportCardinality.ExactlyOne, false, false, CreationPolicy.Any)
        {
            _contractName = contractName;

            ImportType = importType;

            //TODO: handle lazy, metadata, etc...
            ElementType = ImportType.HasElementType ? ImportType.GetElementType() : null;
        }

        public override ImportCardinality Cardinality
        {
            get
            {
                return ImportCardinality.ExactlyOne;
            }
        }
        public override string ContractName
        {
            get
            {
                return _contractName;
            }
        }

        public Type ImportType { get; private set; }
        public Type ElementType { get; private set; }
    }
}
